$('.card-datatable').DataTable({
	 "ajax" : {
		"url" : contextpath + "customerBankCard/list?customerId=" + $("#distributorId").val(),
		"data" : function(d) {
            var query = $("#query").serializeObject();
            query["size"] = d.length;
            query["page"] = (d.start/d.length);
			return query;
		},
		"dataFilter": function(data){
            var json = jQuery.parseJSON( data );
            json.recordsTotal = json.totalElements;
            json.recordsFiltered = json.totalElements;
            json.data = json.content;
 
            return JSON.stringify( json );
        }
	 },
	 "columns": [
         { "data": "bankCardNum" },
         { "data": "bankName" },
         { "data": "customerName" },
         { "data": "bankCardType" }
     ],
     "drawCallback": function( settings ) {
      }
});

$('.distributor-datatable').DataTable({
	 "ajax" : {
		"url" : contextpath + "customer/list?type=1&recommendDistributorId=" + $("#distributorId").val(),
		"data" : function(d) {
            var query = $("#query").serializeObject();
            query["size"] = d.length;
            query["page"] = (d.start/d.length);
			return query;
		},
		"dataFilter": function(data){
            var json = jQuery.parseJSON( data );
            json.recordsTotal = json.totalElements;
            json.recordsFiltered = json.totalElements;
            json.data = json.content;
 
            return JSON.stringify( json );
        }
	 },
	 "columns": [
         { "data": "name" },
         { "data": "levelName" },
         { "data": "phoneNo" },
         {
        	 render : function(data, type, row, meta) {
        		 var province = row.province == null ? '' : row.province;
           		 var city = row.city == null ? '' : row.city;
           		 var area = row.area == null ? '' : row.area;
           		 var address = row.address == null ? '' : row.address;
           		 return province + city + area + address;
        	 }
         },
         {
        	 render : function(data, type, row, meta) {
        		 if(row.auditStatus == '0'){
        			 return '待审核';
        		 }else if(row.auditStatus == '1'){
        			 return '通过';
        		 }else if(row.auditStatus == '2'){
        			 return '拒绝';
        		 }else{
        			 return '未知';
        		 }
             }
         }
     ],
     "drawCallback": function( settings ) {
      }
});

$('.customer-datatable').DataTable({
	 "ajax" : {
		"url" : contextpath + "customer/list?type=0&recommendDistributorId=" + $("#distributorId").val(),
		"data" : function(d) {
           var query = $("#query").serializeObject();
           query["size"] = d.length;
           query["page"] = (d.start/d.length);
			return query;
		},
		"dataFilter": function(data){
           var json = jQuery.parseJSON( data );
           json.recordsTotal = json.totalElements;
           json.recordsFiltered = json.totalElements;
           json.data = json.content;

           return JSON.stringify( json );
       }
	 },
	 "columns": [
        { "data": "name" },
        { "data": "servantName" },
        { "data": "phoneNo" },
        {
       	 render : function(data, type, row, meta) {
       		 var province = row.province == null ? '' : row.province;
       		 var city = row.city == null ? '' : row.city;
       		 var area = row.area == null ? '' : row.area;
       		 var address = row.address == null ? '' : row.address;
       		 return province + city + area + address;
       	 }
        }
    ],
    "drawCallback": function( settings ) {
     }
});

$('.cOrder-datatable').DataTable({
	 "ajax" : {
		"url" : contextpath + "cOrder/list?distributorId=" + $("#distributorId").val(),
		"data" : function(d) {
           var query = $("#query").serializeObject();
           query["size"] = d.length;
           query["page"] = (d.start/d.length);
			return query;
		},
		"dataFilter": function(data){
           var json = jQuery.parseJSON( data );
           json.recordsTotal = json.totalElements;
           json.recordsFiltered = json.totalElements;
           json.data = json.content;

           return JSON.stringify( json );
       }
	 },
	 "columns": [
	     { "data": "customerName" },
	     { "data": "customerPhoneNo" },
        { "data": "distributorName" },
        { "data": "distributorPhoneNo" },
        { "data": "distributorRebate" },
        { "data": "projectName" },
        { "data": "amount" },
        {
       	 render : function(data, type, row, meta) {
       		 if(row.isBalance == '0'){
       			 return '已结算';
       		 }else if(row.isBalance == '1'){
       			 return '未结算';
       		 }else {
       			 return '未知';
       		 }
            }
        }
    ],
    "drawCallback": function( settings ) {
     }
});

$('.cOrder2-datatable').DataTable({
	 "ajax" : {
		"url" : contextpath + "cOrder/list?recommDistributorId=" + $("#distributorId").val(),
		"data" : function(d) {
          var query = $("#query").serializeObject();
          query["size"] = d.length;
          query["page"] = (d.start/d.length);
			return query;
		},
		"dataFilter": function(data){
          var json = jQuery.parseJSON( data );
          json.recordsTotal = json.totalElements;
          json.recordsFiltered = json.totalElements;
          json.data = json.content;

          return JSON.stringify( json );
      }
	 },
	 "columns": [
	     { "data": "customerName" },
	     { "data": "customerPhoneNo" },
       { "data": "distributorName" },
       { "data": "distributorPhoneNo" },
       { "data": "distributorRebate" },
       { "data": "projectName" },
       { "data": "amount" },
       {
      	 render : function(data, type, row, meta) {
      		 if(row.isBalance == '0'){
      			 return '已结算';
      		 }else if(row.isBalance == '1'){
      			 return '未结算';
      		 }else {
      			 return '未知';
      		 }
           }
       }
   ],
   "drawCallback": function( settings ) {
    }
});

$('.withDrawBook-datatable-basic').DataTable({
	 "ajax" : {
		"url" : contextpath + "withdrawBook/list",
		"data" : function(d) {
           var query = {"type":0, "refId" : $("#distributorId").val()};
           query["size"] = d.length;
           query["page"] = (d.start/d.length);
			return query;
		},
		"dataFilter": function(data){
           var json = jQuery.parseJSON( data );
           json.recordsTotal = json.totalElements;
           json.recordsFiltered = json.totalElements;
           json.data = json.content;

           return JSON.stringify( json );
       }
	 },
	 "columns": [
        { "data": "name" },
        {
       	 render : function(data, type, row, meta) {
       		 if(row.type == '0'){
       			 return '渠道商';
       		 }else if(row.type == '1'){
       			 return '服务老师';
       		 }else {
       			 return '未知';
       		 }
            }
        },
        { "data": "withdrawRebate" },
        {
       	 render : function(data, type, row, meta) {
       		 if(row.status == '0'){
       			 return '已提现';
       		 }else if(row.status == '1'){
       			 return '待提现';
       		 }else {
       			 return '未知';
       		 }
            }
        },
        { "data": "customerName" },
        { "data": "bankName" },
        { "data": "bankCardNum" },
        { "data": "createTime" },
        {
           render : function(data,type, row, meta) {
	       		if(row.status == '1'){
	       			return $("#btnGroup").html();
	       		}else {
	       			 return '';
	       		}
           }
       }
    ],
    "drawCallback": function( settings ) {
		 
		 $(".btn-withdraw").click(function(){
			var row = $('.datatable-basic').DataTable().row($(this).closest("tr")).data();
			swal({
				title : "提现",
				text : "确定用户为" + row.name + ",提现金额为" + row.withdrawRebate + "提现成功?",
				type : "warning",
				showCancelButton : true,
				confirmButtonColor : "#DD6B55",
				confirmButtonText : "确定",
				cancelButtonText: "取消",
				closeOnConfirm : false
			},function() {
				$.get(contextpath + "withdrawBook/withDraw/" + row.id, function(d){
					$('.datatable-basic').DataTable().draw();
					swal("提现成功","", "success");
				})
			});
			
		 });
     }
});

$(function(){

	$('select').select2({
	    minimumResultsForSearch: Infinity
	});	
	
})
